﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FITHOU_EDU_Server.Doituong;
using Newtonsoft.Json;

namespace FITHOU_EDU_Server.json
{
    public partial class DemoJsonDotNet : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            demoJson();
        }

        private void demoJson()
        {
            Product product = new Product();
            product.Name = "Apple";
            product.Expiry = new DateTime(2008, 12, 28);
            product.Sizes = new String[] { "Small", "Medium", "Large" };

            string json = JsonConvert.SerializeObject(product);
            //{
            //  "Name": "Apple",
            //  "Expiry": new Date(1230422400000),
            //  "Price": 3.99,
            //  "Sizes": [
            //    "Small",
            //    "Medium",
            //    "Large"
            //  ]
            //}

            //Response.Write("Json is: " + json);

            Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json);
            Response.Write("Name: " + product.Name);
            Response.Write("Expiry: " + product.Expiry + "\n");
        }
    }
}